<?php  
class ControllerArticleArticle extends Controller {
	private $error = array(); 
	
	public function index() { 
		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => '首页',
			'href'      => $this->url->link('common/home'),			
			'separator' => false
		);
		
		$this->load->model('article/category');	
		
		if (isset($this->request->get['path'])) {
			$path = '';
				
			foreach (explode('_', $this->request->get['path']) as $path_id) {
				if (!$path) {
					$path = $path_id;
				} else {
					$path .= '_' . $path_id;
				}
				
				$category_info = $this->model_article_category->getCategory($path_id);
				
				if ($category_info) {
					$this->data['breadcrumbs'][] = array(
						'text'      => $category_info['name'],
						'href'      => $this->url->link('article/category', 'path=' . $path),
						'separator' => ' &raquo; '
					);
				}
			}
		}
		
/* 			$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);

			if ($manufacturer_info) {	
				$this->data['breadcrumbs'][] = array(
					'text'	    => $manufacturer_info['name'],
					'href'	    => $this->url->link('product/manufacturer/product', 'manufacturer_id=' . $this->request->get['manufacturer_id']),					
					'separator' => $this->language->get('text_separator')
				);
			}
		} */
		
		
		if (isset($this->request->get['article_id'])) {
			$article_id = $this->request->get['article_id'];
		} else {
			$article_id = 0;
		}
		
		$this->load->model('article/article');
		
		$article_info = $this->model_article_article->getArticle($article_id);
		
		$this->data['article_info'] = $article_info;
		
		if ($article_info) {
			$url = '';
			
			if (isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
			}
												
			$this->data['breadcrumbs'][] = array(
				'text'      => $article_info['title'],
				'href'      => $this->url->link('article/article', $url . '&article_id=' . $this->request->get['article_id']),
				'separator' => ' &raquo; '
			);			
			
			$this->document->setTitle($article_info['title']);
			$this->document->setDescription($article_info['meta_description']);
			$this->document->setKeywords($article_info['meta_keyword']);
			$this->document->addLink($this->url->link('article/article', 'article_id=' . $this->request->get['article_id']), 'canonical');
			
			$this->data['heading_title'] = $article_info['title'];
			$this->data['article_id'] = $this->request->get['article_id'];
			
			$this->load->model('tool/image');

			if ($article_info['image']) {
				$this->data['popup'] = $this->model_tool_image->resize($article_info['image'], 500,500);
			} else {
				$this->data['popup'] = '';
			}
			
			if ($article_info['image']) {
				$this->data['thumb'] = $this->model_tool_image->resize($article_info['image'], 228,228);
			} else {
				$this->data['thumb'] = '';
			}
            
            if ($article_info['content']) {
				$this->data['content'] = html_entity_decode($article_info['content'], ENT_QUOTES, 'UTF-8');
			} else {
				$this->data['content'] = '';
			}            
            
            if ($article_info['viewed']) {
				$this->data['viewed'] = $article_info['viewed'];
			} else {
				$this->data['viewed'] = '';
			}
			
			$this->model_article_article->updateViewed($this->request->get['article_id']);
            $this->template = 'article/article.tpl';
			
			$this->children = array(
				'article/column_left',
				'common/footer',
				'common/header'
			);
						
			$this->response->setOutput($this->render());
		} else {
			$url = '';
			
			if (isset($this->request->get['path'])) {
				$url .= '&path=' . $this->request->get['path'];
			}
			
			if (isset($this->request->get['manufacturer_id'])) {
				$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
			}			

			if (isset($this->request->get['filter_name'])) {
				$url .= '&filter_name=' . $this->request->get['filter_name'];
			}	
					
			if (isset($this->request->get['filter_tag'])) {
				$url .= '&filter_tag=' . $this->request->get['filter_tag'];
			}
							
			if (isset($this->request->get['filter_description'])) {
				$url .= '&filter_description=' . $this->request->get['filter_description'];
			}
					
			if (isset($this->request->get['filter_category_id'])) {
				$url .= '&filter_category_id=' . $this->request->get['filter_category_id'];
			}
								
      		$this->data['breadcrumbs'][] = array(
        		'text'      => $this->language->get('text_error'),
				'href'      => $this->url->link('product/product', $url . '&product_id=' . $product_id),
        		'separator' => $this->language->get('text_separator')
      		);			
		
      		$this->document->setTitle($this->language->get('text_error'));

      		$this->data['heading_title'] = $this->language->get('text_error');

      		$this->data['text_error'] = $this->language->get('text_error');

      		$this->data['button_continue'] = $this->language->get('button_continue');

      		$this->data['continue'] = $this->url->link('common/home');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
			);
						
			$this->response->setOutput($this->render());
    	}
  	}
	
	public function captcha() {
		$this->load->library('captcha');
		
		$captcha = new Captcha();
		
		$this->session->data['captcha'] = $captcha->getCode();
		
		$captcha->showImage();
	}
	
}
?>